<?php

class HTMLreferees extends HTML_joomleague 
{
  /**
   * display a row in match results table
   *
   * @param object $matchInfo
   * @param object $teamsInfo
   * @param array $favteam
   * @param array $config
   */
  function show_match_row (&$matchInfo, &$teamsInfo, &$favteam, &$config) {
    global $joomleague, $database;
    
    $divLevel = intval(mosGetParam($_REQUEST, 'division', 0));
    $hometeam = $teamsInfo[$matchInfo->matchpart1];
    $guestteam = $teamsInfo[$matchInfo->matchpart2];
    
    ?>
    <tr class="<?php echo $config['class'];?>">
    <?php
    if ($config['show_match_number']==1) {
      ?>
      <td align="left" nowrap="nowrap" valign="top"><?php
      echo $matchInfo->match_number;?>&nbsp;</td>
      <?php
    }
    if ($config['show_events']==1) {
      ?>
      <td align="left" nowrap="nowrap" valign="top"><?php
      $are_there_events = $joomleague->areThereEvents ($matchInfo->match_id);
      if ($are_there_events > 0 || $matchInfo->match_result_detail!="") {
        ?> <a href="javascript:void(0);"
        onclick="switchMenu('info<?php echo $matchInfo->match_id;?>');return false;"
        title="<?php
               echo _JL_SHOW_INFO;?>"> <img
        src="<?php echo _JOOMLA_JL_LIVE_SITE;?>/administrator/components/com_joomleague/images/events.png"
        alt="<?php
               echo _JL_SHOW_INFO;?>"
        title="<?php echo _JL_SHOW_INFO;?>" border="0" /></a> <?php
      }
      ?></td>
      <?php
    }
    if ($joomleague->project_type=='DIVISIONS_LEAGUE' && isset($config['show_division']) && $config['show_division']==1) {
      ?>
      <td nowrap="nowrap" valign="top" style="text-align: center"><?php
      if (isset($config['results_below']) && $config['results_below']==1) {
        $config['spacer'] = '<br />';
      }
      echo $this->showDivisonRemark($hometeam, $guestteam, $config);
      ?></td>
      <?php
    }
    if ($config['show_playground']==1) {
      ?>
      <td nowrap="nowrap" valign="top" style="text-align: center"><?php
      $this->showPlayground($hometeam, $guestteam, $matchInfo, $config['show_playground_alert'], $config['show_playground_name'] );
      ?></td>
      <?php
    }
    if ($config['show_time']==1) {
      ?>
      <td nowrap="nowrap" valign="top"><?php
      echo $this->format_match_time($matchInfo, $joomleague, $config);
      ?></td>
      <?php
    }
    if (isset($config['results_below']) && $config['results_below']==1){
      if ($config['show_logo_small'] > 0) {
        ?>
        <td align="center" valign="top" nowrap="nowrap" style="width: 5%;"><?php
        $this->showClubIcon($hometeam, $config['show_logo_small'], 1);
        echo '<br />';
        $this->showClubIcon($guestteam, $config['show_logo_small'], 1);
        ?></td>
        <?php
      }
      ?>
  
      <td align="left" valign="top" width="30%" nowrap="nowrap"><?php
        $namehighlight=(in_array($hometeam->id, $favteam)) ? 1 : 0;
        $namebold = (isset($team_plan)&&$team_plan->id == $hometeam->id) ? 1 : 0;
        echo $this->formatTeamname ($hometeam, 'm'.$matchInfo->match_id, $config, $namehighlight, $namebold, $matchInfo->project_id);
        echo '<br />';
        $namehighlight=(in_array($guestteam->id, $favteam)) ? 1 : 0;
        $namebold = (isset($team_plan)&&$team_plan->id == $guestteam->id) ? 1 : 0;
        echo $this->formatTeamname ($guestteam, 'm'.$matchInfo->match_id, $config, $namehighlight, $namebold, $matchInfo->project_id);
        ?>
      </td>
        <?php
        echo $this->show_result_below($matchInfo, $config['show_part_results']);
    }
    else {
      // TeamA
      $namehighlight=(in_array($hometeam->id, $favteam)) ? 1 : 0;
      $namebold = (isset($team_plan)&&$team_plan->id == $hometeam->id) ? 1 : 0;
      
      $teamA_html = "";
      if ($config['show_logo_small'] > 0) {
        $teamA_html = '<td align="right" valign="top" nowrap="nowrap" style="width: 5%;">'
                      .$this->getClubIconHtml($hometeam, $config['show_logo_small'])
                      .'</td>';
      }
      $teamA_html .= '<td align="left" valign="top" width="30%" nowrap="nowrap">';
      $teamA_html .= $this->formatTeamname ($hometeam, 'm'.$matchInfo->match_id, $config, $namehighlight, $namebold, $matchInfo->project_id);
      $teamA_html .= '</td>';
      
      $separator = '<td align="left" valign="top" width="5%" nowrap="nowrap">-</td>';

      //Team B
      $namehighlight=(in_array($guestteam->id, $favteam)) ? 1 : 0;
      $namebold = (isset($team_plan)&&$team_plan->id == $guestteam->id) ? 1 : 0;
      
      $teamB_html = "";
      if ($config['show_logo_small'] > 0) {
        $teamB_html = '<td align="right" valign="top" nowrap="nowrap" style="width: 5%;">'
                      .$this->getClubIconHtml($guestteam, $config['show_logo_small'])
                      .'</td>';
      }
      $teamB_html .= '<td align="left" valign="top" width="30%" nowrap="nowrap">';
      $teamB_html .= $this->formatTeamname ($guestteam, 'm'.$matchInfo->match_id, $config, $namehighlight, $namebold, $matchInfo->project_id);
      $teamB_html .= '</td>';
      
      $score_html = '<td align="right" valign="top" nowrap="nowrap">'
                    .$this->show_result($matchInfo, $config['show_part_results'])
                    .'</td>';
                    
      switch ($config['result_style']) {
        case 0 :
          echo $teamA_html.$separator.$teamB_html.$score_html;
          break;
        case 1 :
          echo $teamA_html.$score_html.$teamB_html.'<td>&nbsp;</td>';
          break;
      }
    }
    ?>
    <td align="center" valign="top" nowrap="nowrap"><?php
      if($matchInfo->show_report == 1) {
        echo $this->show_report_icon($matchInfo->match_id);
      }
      ?>
    </td>
    <?php
    if ( $config['show_referee']) {
      ?>
      <td align="right" valign="top" nowrap="nowrap"><?php
        if (!is_null($matchInfo->referee_id) and $matchInfo->referee_id>0) 
        {
          //echo $this->show_referee($matchInfo->referee_id, $joomleague->teams_as_referees);
          if ($joomleague->teams_as_referees) {
          	echo $matchInfo->referee_name;
          }
          else {
          	$reflink = sefRelToAbs( JL_COMPONENT_LINK
          	                 ."&amp;func=showProjectReferee&amp;p=$joomleague->id"
          	                 ."&amp;id=$matchInfo->referee_id".JL_ITEMID_SUFFIX);
          	?>
          	<a href="<?php echo $reflink; ?>">
          	 <?php echo $matchInfo->referee_firstname . ' ' . $matchInfo->referee_lastname; ?>
          	</a>
          	<?php
          }
        } ?>
      </td>
      <?php
    }
    $matchInfo->home = $hometeam->name;
    $matchInfo->away = $guestteam->name;
    if ($joomleague->enable_sb && $config['show_fireboard_link']) {
      ?>
        <td align="right" valign="top" nowrap="nowrap"><?php echo $this->make_forumlink($matchInfo);?>
        </td>
      </tr>
      <?php
    }
    if ($config['show_events']==1 && ($are_there_events > 0 || $matchInfo->match_result_detail!="")) {
      $this->show_events_container_in_results($matchInfo, 'none', $config);
    }
  }
  

  /**
   * displays basic calendar
   * @param array matches
   * @param array config
   */
  function show_basic_plan(&$matches, &$teams, &$config) {
    global $joomleague, $database, $my, $option;
    $divLevel = intval(mosGetParam($_REQUEST, 'division', 0));
    
    ?>
    <table width="96%" align="center" border="0" cellpadding="3"
      cellspacing="0">
      <tr class="sectiontableheader">
      <?php
      $colspan = 6;
      if ( $config['show_events'] ) {
        $colspan++;
        ?>
        <td align="center" width="1%">&nbsp;</td>
        <?php
      }
      if ($joomleague->project_type=='DIVISIONS_LEAGUE' && isset($config['show_division']) && $config['show_division']==1) {
        ?>
        <td nowrap="nowrap" valign="top" style="text-align: center">&nbsp;</td>
        <?php
        $colspan++;
      }
      ?>
      <td align="center"><?php echo _JL_PLAN_MATCHDAY;?></td>
      <?php
      if ($config['show_playground'] > 0 /*0= no display of playground*/)
      {
        $colspan++;
        echo '<td align="center">'._JL_PLAN_PLAYGROUND.'</td>';
      }
      ?>
      <td align="center"><?php echo _JL_ADMIN_EDIT_MATRIX_ROUNDS_DATE;?></td>
      <?php
      if ($config['show_time']) {
        $colspan++;
        ?>
        <td align="center"><?php echo _JL_ADMIN_EDIT_MATRIX_ROUNDS_TIME;?></td>
        <?php
      }
      switch ($config['result_style']) {
        case 1 :
          ?>
          <td/>
          <td align="center" colspan="3"/>
          <td/>
          <?php
          break;        
        default :
        case 0 :
          ?>
          <td/>
          <td/>
          <td/>
          <td align="center" colspan="3"><?php echo _JL_RESULT;?></td>
          <?php
          break;
      }
      if ($config['show_referee'])
      {
        $colspan++;
        echo '<td align="center">'._JL_PLAN_REFEREE.'</td>';
      }
      ?>
      </tr>
      <?php
    
      $user_fav_team_query="SELECT fav_team FROM #__joomleague_tip_members WHERE user_id = ".$my->id."
          AND project_id = ".$joomleague->id;
      $joomleague->_db->setQuery($user_fav_team_query);
      $user_fav_team = $joomleague->_db->loadResult();
    
      $counter=1;
      $k = 0;
      $round_date = "";
      foreach($matches as $v) {
        $match = new Match($database);
        if ( !$match->bind(get_object_vars($v)) ) {
          //$this->debug(1,$match, $v); 
        }
        
        $hometeam = $teams[$match->matchpart1];
        $home_teamtool_id = $hometeam->teamtoolid;
        
        $guestteam = $teams[$match->matchpart2];
        $guest_teamtool_id = $guestteam->teamtoolid;
        
        $class = ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2';
        if ( $match->matchpart1 == $user_fav_team )
        {
          $highlight="highlight";
        }
        else
        {
          $highlight=$class;
        }
        if (!empty($team_plan)) $home = ($match->matchpart1 == $team_plan->id)? sprintf("%s",$hometeam->name) : $hometeam->name;
        else $home = ($match->matchpart2)? sprintf("%s",$hometeam->name) : $hometeam->name;
        if (!empty($team_plan)) $away = ($match->matchpart2 == $team_plan->id)? sprintf("%s",$guestteam->name) : $guestteam->name;
        else $away = ($match->matchpart2)? sprintf("%s",$guestteam->name) : $guestteam->name;
        $homeclub = $hometeam->club_id;
        $awayclub = $guestteam->club_id;
        ?>
    
      <tr class="<?php print $highlight;?>">
      <?php
      if ($config['show_events']==1) {
        ?>
        <td align="left" nowrap="nowrap" valign="top"><?php
        $are_there_events = $joomleague->areThereEvents ($match->match_id);
        if ($are_there_events > 0 || $match->match_result_detail!="") {
          if ($config['use_tabs_events']) {
            ?> <a href="javascript:void(0);"
            onclick="switchMenu('info<?php echo $match->match_id;?>');return false;"
            title="<?php
                   echo _JL_SHOW_INFO;?>"> <img
            src="<?php echo _JOOMLA_JL_LIVE_SITE;?>/administrator/components/com_joomleague/images/events.png"
            alt="<?php
                   echo _JL_SHOW_INFO;?>"
            title="<?php echo _JL_SHOW_INFO;?>" border="0" /></a> <?php
          }
          else {
            ?>
            <img
            src="<?php echo _JOOMLA_JL_LIVE_SITE;?>/administrator/components/com_joomleague/images/events.png"
            title="<?php echo $match->match_result_detail;?>" border="0" />
            <?php
          }
        }
        ?></td>
        <?php
      }
      if ($joomleague->project_type=='DIVISIONS_LEAGUE' && isset($config['show_division']) && $config['show_division']==1) {
        ?>
        <td nowrap="nowrap" valign="top" style="text-align: center"><?php
        echo $this->showDivisonRemark($hometeam, $guestteam, $config);
        ?></td>
        <?php
      }
      ?>
        <td align="center" width="5%"><?php echo '<a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showResults&amp;p='.$match->project_id
        .'&amp;r='.$v->matchcode.JL_ITEMID_SUFFIX).'">'.$v->matchcode.'</a>';?></td>
        <?php
        if ($config['show_playground'] > 0 /*0= no display of playground*/) {
          echo '<td align="center" nowrap="nowrap">';
          $this->showPlayground($hometeam, $guestteam, $v, $config['show_playground_alert'], $config['show_playground_name'] );
          echo '</td>';
        }
        ?>
        <td align="center" nowrap="nowrap" width="10%"><?php 
        if (!strstr($match->match_date , "0000-00-00")) echo mosFormatDate($match->match_date, _JL_BASIC_CALENDAR_DATE,0);
        else echo "";
        ?></td>
        <?php
        if ($config['show_time']) {
          ?>
        <td align="center" nowrap="nowrap" width="10%"><?php 
        echo $this->format_match_time($match, $joomleague, $config);
        ?></td>
        <?php
    }
    $teamA = '<td align="right" nowrap="nowrap">
              <a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showPlan&amp;p='.$match->project_id
                    .'&amp;tid='.$match->matchpart1.JL_ITEMID_SUFFIX).'">'
               .$home
              .'</a>';
    if ($config['show_logo_small']) { 
      $teamA .= " ".$this->getClubIconHtml($hometeam, 1);
    }
    $teamA .= '</td>';
    
    $separator ='<td width="10" align="center">-</td>';
    
    $teamB = '<td align="left" nowrap="nowrap">';
    if ($config['show_logo_small']) { 
      $teamB .= $this->getClubIconHtml($guestteam, 1)." ";
    }
    $teamB .= '<a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showPlan&amp;p='.$match->project_id
                    .'&amp;tid='.$match->matchpart2.JL_ITEMID_SUFFIX).'">'
               .$away
              .'</a>'
              .'</td>';
                            
    $score = '<td align="right">';
    if ($match->alt_decision==0) {
      $e1=$match->matchpart1_result;
      $e2=$match->matchpart2_result;
    }
    else {
      $e1=(isset($match->matchpart1_result_decision)) ? $match->matchpart1_result_decision : 'X';
      $e2=(isset($match->matchpart2_result_decision)) ? $match->matchpart2_result_decision : 'X';
      $e2 .= ' <img src="'.JL_TEMPLATE_FOLDERS_URL.'/images/court.gif" border="0" alt="'.$match->decision_info.'" title="'.$match->decision_info
      .'" border="0" />';
    }
    $score .= sprintf('%s</td><td valign="top" width="1px">-</td><td align="left" valign="top" nowrap>%s',$e1,$e2);
    $score .= '</td>';
    
    switch ($config['result_style']) {
        case 1 :
          echo $teamA.$score.$teamB;
          break;
        default;
        case 0 :
          echo $teamA.$separator.$teamB.$score;
          break;
    }
    
    if ($config['show_referee'])
    {
      ?>
      <td align="center" valign="top" nowrap="nowrap"><?php
      //echo $this->show_referee($match->referee_id, $joomleague->teams_as_referees );
        if ($joomleague->teams_as_referees) echo $v->referee_name;
        else {
            $reflink = sefRelToAbs( JL_COMPONENT_LINK
                             ."&amp;func=showProjectReferee&amp;p=$joomleague->id"
                             ."&amp;id=$v->referee_id".JL_ITEMID_SUFFIX);
            ?>
            <a href="<?php echo $reflink; ?>">
             <?php echo $v->referee_firstname . ' ' . $v->referee_lastname; ?>
            </a>
            <?php
          }
      ?></td>
      <?php
    }
    ?>
      </tr>
      <?php
      if ($config['show_events']==1 && $config['use_tabs_events'] && ($are_there_events > 0 || $match->match_result_detail!="")) {
        $config['colspan'] = $colspan;
        $this->show_events_container_in_results($match, 'none', $config);
      }
      $k = 1 - $k;
      $counter++;
    }
    ?>
    </table>
    <?php
  }
}
?>